/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data.logic;

import data.ArmyBuildingType;
import data.Building;
import data.BuildingType;
import data.ProductionBuildingType;
import data.TownCenterBuildingType;
import java.awt.Point;
import java.util.Vector;

/**
 *
 * @author Jonas
 */
public class BuildingSquareTypeFactory {

    private static BuildingSquareTypeFactory instance = null;
    private Vector<BuildingType> types = null;

    public BuildingSquareTypeFactory() {

    }

    public static BuildingSquareTypeFactory getInstance() {
        if (instance == null) {
            instance = new BuildingSquareTypeFactory();
        }
        return instance;
    }

    public BuildingSquareType makeBuilding(String buildingTypeName, Point position) {

        Building building = new Building();

        for (BuildingType buildingType : getTypes()) {
            if (buildingType.getName().equals(buildingTypeName)) {

                if (buildingType instanceof TownCenterBuildingType) {
                    building.setType(0);
                    building.setCapacity(-1);
                }

                if (buildingType instanceof ProductionBuildingType) {

                    ProductionBuildingType productionBT = (ProductionBuildingType) buildingType;
                    building.setCapacity(productionBT.getDefaultCapacity());
                    building.setResourceType(productionBT.getResourceType());
                    building.setType(1);
                }
                if (buildingType instanceof ArmyBuildingType) {
                    building.setCapacity(-1);
                    building.setType(2);
                }
                building.setImageUrl(buildingType.getImageUrl());
                building.setName(buildingTypeName);
                building.setLevel(1);
                building.setCost(buildingType.getCost());

                building.setStatusDescription("Up And Running");
                building.setTimeLeft(-1);
                building.setStrength(buildingType.getDefaultStrength());
                building.setMaxLevel(50);
                building.setLocationX(position.x);
                building.setLocationY(position.y);

            }
        }
        BuildingSquareType buildingSqTp = new BuildingSquareType(building);
        return buildingSqTp;
    }

    public void setBuildingTypes(Vector<BuildingType> types) {
        this.types = types;

    }

    public Vector<BuildingType> getTypes() {
        return types;
    }
}
